﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DomainModel
{   
    public class SmartNoteController
    {
        public SmartNoteController(ISmartNoteView view, ISmartNoteModel model)
        {
            View = view;
            Model = model;
        }

        public ISmartNoteView View {get;set;}
        public ISmartNoteModel Model { get; set; }

        public void onLoad()
        {
            View.clearNotes();
            View.clearTags();

            IList<Note> notes = Model.findNotes(0);

            foreach (Note note in notes)
            {
                View.addNote(note);
                IList<Tag> tags = Model.getTags(note.Id);
                foreach(Tag tag in tags)
                {
                    View.addTagToNote(tag, note.Id);
                }
            }

            onLoadSubTags(0);
        }

        void onLoadSubTags(int parentTag)
        {
            IList<Tag> tags = Model.getChildrenTags(parentTag);
            foreach (Tag tag in tags)
            {
                View.addTag(tag, parentTag);
                onLoadSubTags(tag.Id);
            }
        }
    }
}
